const WorkModel = require("../../models/WorkModel")

const WorkService ={
    
    add:async({title,introduction,detail,cover,editTime})=>{
        console.log("数据库的模型处理")

        return WorkModel.create({
            title,introduction,detail,cover,editTime
        })
    },

        getList:async({_id})=>{//{}是查询所有记录，【】是要的字段
        return _id? WorkModel.find({_id}) : WorkModel.find({})
    }, 
        delList:async ({_id})=>{
        return WorkModel.deleteOne({_id})
    },
    updateList:async({title,introduction,detail,_id,cover,editTime})=>{
        if(cover){
            return WorkModel.updateOne({_id},{title,introduction,detail,cover,editTime})
        }else{
            return WorkModel.updateOne({_id},{title,introduction,detail,editTime})
        }
        
    },

    // publish:async({_id,isPublish,editTime})=>{
    //     return NewsModel.updateOne({
    //         _id
    //     },{
    //         isPublish,
    //         editTime
    //     })
    // },

    
}

module.exports =WorkService